<template lang="jade">
#borrow-history.current-lending
  .weui-loadmore(v-show="!ready")
    i.weui-loading
    span.weui-loadmore__tips 加载中
  .history-list(v-show="ready")
    .weui-loadmore.weui-loadmore_line(v-show="bookList.length === 0")
        .weui-loadmore__tips 暂无数据
    .list-item(v-for='book in bookList')
      .weui-flex.book-info
        .left.weui-flex__item
          h3.books-name {{book.TITLE}}
          .author 作者 {{book.AUTHOR}}
        .status-warning {{ actionLabel(book.ACTION) }}
      .weui-flex
        .weui-flex__item 借书日期:
        div {{book.DUETIME}}
      .bottom.hide
        a.btn-green.weui-btn.weui-btn_mini.weui-btn_primary(@click='$emit("renew", book.ItemId)') 续借
</template>

<script>
import api from '../../api-new'

export default {
  data () {
    return {
      ready: false,
      bookList: []
    }
  },
  created () {
    const uid = this.$cookie.get('uid')
    if (!uid) return
    api.borrowHistory(uid).then(data => {
      this.bookList = data.data.list
    }).catch(error => {
      console.log(error)
    }).finally(() => {
      this.ready = true
    })
  },
  methods: {
    actionLabel (action) {
      return action === 'LOAN' ? '借书' : '还书'
    }
  }
}
</script>

<style>
.history-list {
  border-top: 1px solid #eee;
}
</style>
